package com.ruoyi.jjyh.controller;

import java.util.List;

import com.ruoyi.jjyh.service.IJjyhOrderGoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjyh.domain.JjyhOrderGoods;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单商品表Controller
 * 
 * @author ruoyi
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/jjyh/goods")
public class JjyhOrderGoodsController extends BaseController
{
    private String prefix = "jjyh/goods";

    @Autowired
    private IJjyhOrderGoodsService jjyhOrderGoodsService;

    @RequiresPermissions("jjyh:goods:view")
    @GetMapping()
    public String goods()
    {
        return prefix + "/goods";
    }

    /**
     * 查询订单商品表列表
     */
    @RequiresPermissions("jjyh:goods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JjyhOrderGoods jjyhOrderGoods)
    {
        startPage();
        List<JjyhOrderGoods> list = jjyhOrderGoodsService.selectJjyhOrderGoodsList(jjyhOrderGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单商品表列表
     */
    @RequiresPermissions("jjyh:goods:export")
    @Log(title = "订单商品表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JjyhOrderGoods jjyhOrderGoods)
    {
        List<JjyhOrderGoods> list = jjyhOrderGoodsService.selectJjyhOrderGoodsList(jjyhOrderGoods);
        ExcelUtil<JjyhOrderGoods> util = new ExcelUtil<JjyhOrderGoods>(JjyhOrderGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 新增订单商品表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单商品表
     */
    @RequiresPermissions("jjyh:goods:add")
    @Log(title = "订单商品表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JjyhOrderGoods jjyhOrderGoods)
    {
        return toAjax(jjyhOrderGoodsService.insertJjyhOrderGoods(jjyhOrderGoods));
    }

    /**
     * 修改订单商品表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JjyhOrderGoods jjyhOrderGoods = jjyhOrderGoodsService.selectJjyhOrderGoodsById(id);
        mmap.put("jjyhOrderGoods", jjyhOrderGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单商品表
     */
    @RequiresPermissions("jjyh:goods:edit")
    @Log(title = "订单商品表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JjyhOrderGoods jjyhOrderGoods)
    {
        return toAjax(jjyhOrderGoodsService.updateJjyhOrderGoods(jjyhOrderGoods));
    }

    /**
     * 删除订单商品表
     */
    @RequiresPermissions("jjyh:goods:remove")
    @Log(title = "订单商品表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jjyhOrderGoodsService.deleteJjyhOrderGoodsByIds(ids));
    }
}
